package inspur.dao;

import inspur.common.ConnectionUtils;
import inspur.entity.logObject;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class logDao {
    Connection conn=null;
    PreparedStatement pstm=null;
    ResultSet rs=null;
    //记录日志
    public int log(logObject log){

        //得到数据库对象
        conn= ConnectionUtils.getConnection();
        int flag=0;//
        try {
            //发送sql文


            String sql="INSERT  INTO log(date,user,keyoperations,warninglevel,ip)VALUES (?,?,?,?,?)";
            pstm= conn.prepareStatement(sql);
            pstm.setString(1, log.getDate());
            pstm.setString(2, log.getUserid());
            pstm.setString(3, log.getKeyoperations());
            pstm.setString(4, log.getWarninglevel());
            pstm.setString(5, log.getIP());
            int num=pstm.executeUpdate();

            //处理结果集
            if (num==1){
                flag=2;
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }finally{

            //释放资源
            ConnectionUtils.close(rs, pstm, conn);
        }
        return flag;

    }
}
